import time
import random
from datetime import datetime


def gen_random_time():
    start = time.mktime((1971, 1, 1, 0, 0, 0, 0, 0, 0))
    end = float(int(time.time()))
    t = random.randint(start, end)
    date_tuple = time.localtime(t)
    date = time.strftime('%Y-%m-%d %H:%M:%S', date_tuple)
    return {
        'year': date_tuple.tm_year,
        'mon': date_tuple.tm_mon,
        'day': date_tuple.tm_mday,
        'hour': date_tuple.tm_hour,
        'min': date_tuple.tm_min,
        'sec': date_tuple.tm_sec,
        'time': t,
        'date': date
    }


def get_time_result(mode: str = 'date'):
    random_time = gen_random_time()
    random_date = random_time.get('date')
    date_dict = datetime.strptime(random_date, '%Y-%m-%d %H:%M:%S')
    if not isinstance(mode, str) or not mode or mode == 'date':
        return date_dict.date()
    elif mode == 'time':
        return date_dict.time()
    return date_dict


if __name__ == '__main__':
    print(get_time_result())
